package com.LeeCode;

/**
 * 统计得分小于 K 的子数组数目
 */

public class Code2302 {
    public static void main(String[] args) {
        int[] nums = {2, 1, 4, 3, 5};
        System.out.println(new Code2302().countSubarrays(nums, 10));
    }

    public long countSubarrays(int[] nums, long k) {
        long ans = 0, sum = 0;
        int left = 0;

        for (int right = 0; right < nums.length; right++) {
            sum += nums[right];
            while (sum * (right - left + 1) >= k) {
                sum -= nums[left];
                left++;
            }
            ans += right - left + 1;
        }

        return ans;
    }
}
